/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.chinapnr.result;

import java.util.LinkedHashMap;

import org.grayrabbit.pay.chinapnr.common.PnrConstants;

/**
 * 交易结果
 * 
 * @author wy
 * @version $Id: PayResult.java, v 0.1 2012-11-4 下午9:53:10 wy Exp $
 */
public class ChinapnrPayResult {

    /**处理状态*/
    private PayStatusEnum status;

    /**返回码 status为ERROR才有*/
    private String     responseCode;

    /**原因 status为ERROR才有*/
    private String     cause;

    private ChinapnrPayResult() {

    }

    /**
     * 转换返回结果
     * 
     * @param map
     */
    public static ChinapnrPayResult convertResponseMap(LinkedHashMap<String, String> map) {
        ChinapnrPayResult result = new ChinapnrPayResult();
        
        String code = map.get("RespCode");
        String errMsg = map.get("ErrMsg");
        if (!"00".equals(code) && !"99".equals(code)) {
            result.setStatus(PayStatusEnum.ERROR);
            result.setResponseCode(code);
            String cause = PnrConstants.TRADE_REQUEST_MAP.get(code);
            if("XX".equalsIgnoreCase(code)){
                cause+=errMsg;
            }
            result.setCause(cause == null ? errMsg : cause);
        } else {
            if ("00".equals(code)) {
                result.setStatus(PayStatusEnum.SUCCESS);
            } else {
                result.setStatus(PayStatusEnum.IN_HAND);
            }
        }
        return result;
    }

    /**
     * Getter method for property <tt>status</tt>.
     * 
     * @return property value of status
     */
    public PayStatusEnum getStatus() {
        return status;
    }

    /**
     * Setter method for property <tt>status</tt>.
     * 
     * @param status value to be assigned to property status
     */
    public void setStatus(PayStatusEnum status) {
        this.status = status;
    }

    /**
     * Getter method for property <tt>responseCode</tt>.
     * 
     * @return property value of responseCode
     */
    public String getResponseCode() {
        return responseCode;
    }

    /**
     * Setter method for property <tt>responseCode</tt>.
     * 
     * @param responseCode value to be assigned to property responseCode
     */
    public void setResponseCode(String responseCode) {
        this.responseCode = responseCode;
    }

    /**
     * Getter method for property <tt>cause</tt>.
     * 
     * @return property value of cause
     */
    public String getCause() {
        return cause;
    }

    /**
     * Setter method for property <tt>cause</tt>.
     * 
     * @param cause value to be assigned to property cause
     */
    public void setCause(String cause) {
        this.cause = cause;
    }

}
